package com.ruoyi.womp.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.dao.DuplicateKeyException;
import org.springframework.stereotype.Service;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.womp.domain.WompOsiPlan;
import com.ruoyi.womp.mapper.WompOsiPlanMapper;
import com.ruoyi.womp.service.IWompOsiPlanService;

/**
 * 巡检计划Service业务层处理
 * 
 * @author mzz
 * @date 2023-05-11
 */
@Service
public class WompOsiPlanServiceImpl implements IWompOsiPlanService {
	@Autowired
	private WompOsiPlanMapper wompOsiPlanMapper;

	/**
	 * 查询巡检计划
	 * 
	 * @param id 巡检计划主键
	 * @return 巡检计划
	 */
	@Override
	public WompOsiPlan selectWompOsiPlanById(Integer id) {
		return wompOsiPlanMapper.selectWompOsiPlanById(id);
	}

	/**
	 * 查询巡检计划列表
	 * 
	 * @param wompOsiPlan 巡检计划
	 * @return 巡检计划
	 */
	@Override
	public List<WompOsiPlan> selectWompOsiPlanList(WompOsiPlan wompOsiPlan) {
		return wompOsiPlanMapper.selectWompOsiPlanList(wompOsiPlan);
	}

	/**
	 * 新增巡检计划
	 * 
	 * @param wompOsiPlan 巡检计划
	 * @return 结果
	 */
	@Override
	public int insertWompOsiPlan(WompOsiPlan wompOsiPlan) throws DuplicateKeyException {
		wompOsiPlan.setCreateTime(DateUtils.getNowDate());
		try {
			return wompOsiPlanMapper.insertWompOsiPlan(wompOsiPlan);
		} catch (DuplicateKeyException e) {
			throw new DuplicateKeyException("衡器已存在当前类型巡检计划");
		}
	}

	/**
	 * 修改巡检计划
	 * 
	 * @param wompOsiPlan 巡检计划
	 * @return 结果
	 * @throws Exception
	 */
	@Override
	public int updateWompOsiPlan(WompOsiPlan wompOsiPlan) throws DuplicateKeyException {
		wompOsiPlan.setUpdateTime(DateUtils.getNowDate());
		try {
			return wompOsiPlanMapper.updateWompOsiPlan(wompOsiPlan);
		} catch (DuplicateKeyException e) {
			throw new DuplicateKeyException("衡器已存在当前类型巡检计划");
		}
	}

	/**
	 * 批量删除巡检计划
	 * 
	 * @param ids 需要删除的巡检计划主键
	 * @return 结果
	 */
	@Override
	public int deleteWompOsiPlanByIds(String ids) {
		return wompOsiPlanMapper.deleteWompOsiPlanByIds(Convert.toStrArray(ids));
	}

	/**
	 * 删除巡检计划信息
	 * 
	 * @param id 巡检计划主键
	 * @return 结果
	 */
	@Override
	public int deleteWompOsiPlanById(Integer id) {
		return wompOsiPlanMapper.deleteWompOsiPlanById(id);
	}
}
